package com.fbs.wowo.util.common;

import com.fbs.wowo.WowoApplication;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Property {
    private static final Properties Properties = new Properties();
    private static String[] args = null;
    private static String filename = "application-wo.properties";
    private static final String propPre = "application-";
    private static final String propSuf = ".properties";

    static {
        try {
            args = WowoApplication.args;
            if (args != null) {
                try {
                    for (String arg : args) {
                        if (arg.startsWith("--spring.profiles.active=")) {
                            String[] ss = arg.split("=");
                            filename = propPre + ss[1] + propSuf;
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            InputStream in = Property.class.getClassLoader().getResourceAsStream(filename);
            Properties.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static String getProperty(String key) {
        return Properties.getProperty(key);
    }
}
